import MysInfo from "../../genshin/model/mys/mysInfo.js"
import NoteUser from "../../genshin/model/mys/NoteUser.js"
import BH3MysApi from "./mysApi.js"

class MysCfg {
    constructor() {
    }

  async othergame(e) {
    let user = await NoteUser.create(e)
    if (!user.hasCk) {
      await e.reply('当前尚未绑定Cookie')
      return false
    }
    let mys = user.getMysUser(e)
    let uid = await MysInfo.getUid(e, false)
    let ck = mys.ck
    let game = e.game
    let res, game_biz, region
    let mysApi = new BH3MysApi('', ck, { game })
    if (game == 'bh2') {
      res = await mysApi.getData('bh2_cn')
      if (!res || res?.retcode !== 0) {
        await e.reply('用户数据获取失败')
        return false
      }
    } else {
      res = await mysApi.getData('bh3_cn')
      if (!res || res?.retcode !== 0) res = await mysApi.getData('bh3_global')
      if (!res || res?.retcode !== 0) {
        await e.reply('用户数据获取失败')
        return false
      }
    }

    let data = res.data.list.find(item => item.game_uid === uid)
    if (data) {
      game_biz = data.game_biz,
      region = data.region
    } else {
      game_biz = '',
      region = ''
    }
    return { uid, ck, game_biz, region }
  }
}

export default new MysCfg()